Skip to content

Fix JS editor syntax highlighting regression (#5334)#5339

Closed
severe77 wants to merge 1 commit intosugarlabs:masterfrom
severe77:fix-js-editor-highlighter
Closed

Fix JS editor syntax highlighting regression (#5334)#5339
severe77 wants to merge 1 commit intosugarlabs:masterfrom
severe77:fix-js-editor-highlighter

Conversation

@severe77
Copy link
Contributor

Summary

This PR fixes a regression in the JavaScript editor where syntax highlighting
fails due to a highlight.js API mismatch.

Problem

The current code assumes the presence of hljs.highlightElement, which is not
available in older highlight.js versions that are still used in some setups.
As a result, the editor opens without syntax highlighting, even though the
highlighter library is loaded.

While the issue mentions load order, the root cause here is an API mismatch.
The highlighter is already loaded, but the expected DOM-highlighting method
differs across highlight.js versions.

Solution

This change keeps the existing behavior for newer highlight.js versions and
adds a backward-compatible fallback to hljs.highlightBlock when
highlightElement is not available. This restores syntax highlighting across
both old and new highlight.js APIs without changing load order or introducing
side effects.

Why this approach

  • Prevents silent failures where highlighting does not run
  • Fully resolves the reported regression instead of only guarding the error
  • Maintains compatibility across different highlight.js versions
  • Minimal and safe change scoped to the editor highlighting logic

Fixes #5334

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@walterbender
Copy link
Member

Another (earlier) PR addressed this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] highlighter not loading

2 participants